<template>
	<view class="history_apply">
		<xbd-pages-content title="填报历史">
			<template #content>
				<view class="content">
					<uni-list :border="false">
						<xbd-perf-card  v-for="item in showList" :key="item._id" :myInfo="item" @clickPreformanceCard="details(item._id,item.performance_statue)"></xbd-perf-card>
						<xbd-null-list v-if="!showList.length"></xbd-null-list>
						<xbd-loading-more :status-num="statusNum" :is-load-more="isLoadMore"></xbd-loading-more>
					</uni-list>

				</view>
			</template>
		</xbd-pages-content>
	</view>
</template>

<script>
	import { Performance } from '@/api/index.js';
	export default {
		data() {
			return {
				statusNum: 0,
				isLoadMore: false,
				type: '',
				showList:[],
				queryInfo:{
					type:"apply",
					page: 1,
					perpage: 10
				}
			};
		},
		methods: {
			// eventCallback(obj) {
			// 	console.log('我的历史页面', obj);
			// 	// console.log('我的历史页面2', this.showList);
			// 	// this.showList.forEach(item => {
			// 	// 	if (item._id == obj) {
			// 	// 		item.performance_statue = '0';
			// 	// 	}
			// 	// });
			// 	this.queryInfo.page = 1
			// 	this.getList()
			// 	// 强制刷新回到顶部
			// 	uni.pageScrollTo({
			// 	    scrollTop: 0,
			// 	});
			// },
			modifyDetails(val,id){
				console.log('我的历史页面3',val)
				console.log('我的历史页面3',id)
				this.showList.forEach(item => {
					if (item._id == id) {
						item.details = val
						console.log(item.details,'details',val)
					}
				});
				console.log(this.showList,'modifyDetails2')
			},
			async getList() {
				try {
					this.$showLoading('加载中');
					const res = await Performance.getHistory(this.queryInfo);
					uni.hideLoading();
					if(res.data.success){
						this.total = res.data.data.total;
						this.showList = res.data.data.data
						if (res.data.data.data.length === this.queryInfo.perpage) {
							this.isLoadMore = true;
							this.statusNum = 2;
						}
					}else{
						uni.showToast({
								title: res.data.msg,
								icon: 'none',
							})
					}
				} catch (e) {
					uni.hideLoading();
					console.log(e);
				}
			},
			loadmore() {
				if (this.visible) {
			
				} else {
					this.queryInfo.page++;
					this.statusNum = 1;
					this.isLoadMore = true;
					this.loadmoreList();
				}
			},
			// 加载数据
			async loadmoreList() {
				try {
					this.$showLoading('加载中');
					const res = await Performance.getHistory(this.queryInfo);
					console.log(res)
					uni.hideLoading();
					if (res.data.success) {
						this.showList = this.showList.concat(res.data.data.data);
						if (res.data.data.data.length === this.queryInfo.perpage) {
							this.statusNum = 2;
							// this.isLoadMore=false
						} else {
							this.statusNum = 0;
						}
					} else {
						this.queryInfo.page--;
						this.statusNum = 0;
					}
				} catch (e) {
					uni.hideLoading();
					this.queryInfo.page--;
					console.log(e);
				}
			},
			details(id,val) {
				console.log(id)
					uni.navigateTo({
						url: `./auditForm?msg=1&id=${id}&state=${val}`,
					})
				
			},
			
		},
		onLoad() {
			// this.getList()
			// uni.$on('performanceHistory', this.eventCallback);
			// uni.$on('modifyDetails', this.modifyDetails);
			// uni.$on('refresh', this.eventCallback);
		},
		onUnload() {
			// uni.$off('performanceHistory');
			// uni.$off('modifyDetails');
			
			// uni.$off('refresh');
		},
		onShow(){
			this.queryInfo.page = 1
			this.getList()
			// 强制刷新回到顶部
			uni.pageScrollTo({
			    scrollTop: 0,
			});
		},
		// 触底触发
		onReachBottom() {
			// 当下拉组件显示状态 并且显示不是没有数据了 时才进行下拉加载
			if (this.isLoadMore && this.statusNum !== 0 && this.total/10 >this.queryInfo.page) {
				this.loadmore();
			}
			if(this.total/10 >this.queryInfo.page){
				
			}else{
				this.isLoadMore = false
			}
		}
	}
</script>

<style lang="scss" scoped>
	::v-deep .uni-list {
		background-color: #f8f8f8;
	}
	::v-deep .data-v-1a79304c {
		white-space: nowrap;
	}
	
	::v-deep .uni-easyinput__content {
		border-radius: 8rpx;
		min-height: 32px;
	}
	
	::v-deep .uni-input-wrapper {
		text-align: center;
		white-space: nowrap;
	}
</style>
